﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mailer.Utilities
{
	public class Configuration
	{

		static string _RootURL = "";

		public static string RootURL
		{
			get { return _RootURL; }
			set { _RootURL = value; }
		}



		static string _RootURL2 = "";

		public static string RelativeRootURL
		{
			get { return _RootURL2; }
			set { _RootURL2 = value; }
		}


		static string _SystemMailsFromName = "";

		public static string SystemName
		{
			get { return Configuration._SystemMailsFromName; }
			set { Configuration._SystemMailsFromName = value; }
		}


		static string _SystemMailsFromEmail = "";

		public static string SystemEmail
		{
			get { return Configuration._SystemMailsFromEmail; }
			set { Configuration._SystemMailsFromEmail = value; }
		}
		 
		static int _TimerInterval;

		public static int SendTimerInterval
		{
			get { return Configuration._TimerInterval; }
			set { Configuration._TimerInterval = value; }
		}


		static int _SendThreads;

		public static int SendThreads
		{
			get { return Configuration._SendThreads; }
			set { Configuration._SendThreads = value; }
		}


		static int _BatchSize;

		public static int SendBatchSize
		{
			get { return Configuration._BatchSize; }
			set { Configuration._BatchSize = value; }
		}
		static int _PollTimerInterval;

		public static int PollTimerInterval
		{
			get { return Configuration._PollTimerInterval; }
			set { Configuration._PollTimerInterval = value; }
		}

		static int _PollLimit;

		public static int PollLimit
		{
			get { return Configuration._PollLimit; }
			set { Configuration._PollLimit = value; }
		}
				
		static string _BounceSmtpAddress = "";

		public static string BounceSmtpServerAddress
		{
			get { return Configuration._BounceSmtpAddress; }
			set { Configuration._BounceSmtpAddress = value; }
		}





		public static void Initialize()
		{

			RootURL = System.Configuration.ConfigurationManager.AppSettings["NMailer.RootURL"];
			RelativeRootURL = System.Configuration.ConfigurationManager.AppSettings["NMailer.RelativeRootURL"];
			SystemEmail = System.Configuration.ConfigurationManager.AppSettings["NMailer.SystemEmail"];
			SystemName = System.Configuration.ConfigurationManager.AppSettings["NMailer.SystemName"];
			BounceSmtpServerAddress = System.Configuration.ConfigurationManager.AppSettings["NMailer.BounceSmtpServerAddress"];

			int timerinterval = 0;
			int.TryParse(System.Configuration.ConfigurationManager.AppSettings["NMailer.SendInterval"], out timerinterval);
			SendTimerInterval = timerinterval;

			int batchsize = 10;
			int.TryParse(System.Configuration.ConfigurationManager.AppSettings["NMailer.SendBatchSize"], out batchsize);
			if (batchsize < 1)
				batchsize = 1;
			SendBatchSize = batchsize;

			int pollinterval = 0;
			int.TryParse(System.Configuration.ConfigurationManager.AppSettings["NMailer.PollInterval"], out pollinterval);
			PollTimerInterval = pollinterval;

			int polllimit = 5;
			int.TryParse(System.Configuration.ConfigurationManager.AppSettings["NMailer.PollLimit"], out polllimit);
			if (polllimit < 1)
				polllimit = 1;
			PollLimit = polllimit;

			int sentthreads = 1;
			int.TryParse(System.Configuration.ConfigurationManager.AppSettings["NMailer.SendThreads"], out sentthreads);
			if (sentthreads < 1)
				sentthreads = 1;
			SendThreads = sentthreads;

		}


		public static string VersionString
		{
			get { 
				// typeof(Mailer.Utilities.Configuration).Assembly.
				return "NMailer v0.02 svnrev" + Misc.Revision+" "+Misc.BuildDate;
			}
		}
	}
}
